/*
 *  Copyright 2010 Mahbub Mozadded Sowrov.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package com.sowrov.gui.model.tablemodel;

import java.util.Hashtable;

import javax.swing.table.TableCellEditor;

/**
 * A model to hold different TableCellEditor for every
 *
 * @author Sowrov
 */
public class JTableXEditorModel {

    private Hashtable cellEditor;

    private int totalCol;

    public JTableXEditorModel(final int totalCol) {
        this.totalCol = totalCol;
        cellEditor = new Hashtable();
    } // end JTableXEditorModel()

    /**
     * Get the cell editor of a specific cell
     * @param row row no.
     * @param col column no.
     * @return cell editor
     */
    public final TableCellEditor getCellEditor(final int row, final int col) {
        return (TableCellEditor) cellEditor.get(new Integer((row * totalCol) + col));
    } // end getCellEditor()

    /**
     * 
     * @param row
     * @param col
     * @param tce
     */
    public final void addCellEditor(final int row, final int col, final TableCellEditor tce) {
        int num = (row * totalCol) + col;
        cellEditor.put(new Integer(num), tce);
    } // end addCellEditor()

    public final void removeCellEditor(final int row, final int col) {
        int num = (row * totalCol) + col;
        cellEditor.remove(new Integer(num));
    } // end removeCellEditor()
} // end JTableXEditorModel

